﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Backend.JYD.BLL.Bid;
using Backend.JYD.Model.Bid;
using Backend.JYD.Common;
using Backend.JYD.RunTime;

namespace Backend.JYD.Web.Controllers
{
    public class InviteController : BaseController
    {
        //
        // GET: /Invite/
        InviteInfoBLL bll = new InviteInfoBLL();
        public ActionResult Index()
        {
            //增加当前员工条件
            //var list = bll.GetInviteInfoByPage(new Model.PageInfo() { PageIndex = 1, PageSize = 20 });
            //return View(list.PageList);
            return View();
        }

        //
        // GET: /Invite/Details/5

        public ActionResult Details(Int64 inviteId)
        {
            var info = bll.GetdInviteInfoByInviteId(inviteId);
            return View(info);
        }

        //
        // GET: /Invite/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Invite/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                


                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Invite/Edit/5

        public ActionResult Edit(Int64 inviteId)
        {
            var info = bll.GetdInviteInfoByInviteId(inviteId);
            return View(info);
        }

        //
        // POST: /Invite/Edit/5

        [HttpPost]
        public ActionResult Edit(Int64 inviteId, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                InviteInfo info = new InviteInfo();
                info.CreateTime = DateTime.Now;
                info.CustNo = collection["CustNo"];
                info.IntentId = NumberHelper.StrToInt64(collection["IntentId"]);
                info.InviteId = NumberHelper.StrToInt64(collection["InviteId"]);
                info.LoanMoney = NumberHelper.StrToDecimal(collection["LoanMoney"]);
                info.Rate = NumberHelper.StrToDecimal(collection["Rate"]);
                info.OpId = this.EmpId;
                info.Status = (int)InviteInfoBLL.enumInviteStatus.初始;
                info.Term = NumberHelper.StrToInt(collection["Term"]);
                info.Type = 1;
                info.UpdateTime = DateTime.Now;

                if (info.InviteId > 0)
                    bll.UpdateInviteInfo(info);
                else
                    info.InviteId = bll.AddInviteInfo(info);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

    }
}
